import os

from dao.install_cluster import spark, hadoop
from dao.project_url import url
from myadmin.models import Cluster

url = url()


def oneClick_deploy(num, types):
    if Cluster.objects.exists():
        start = Cluster.objects.last().id + 1
    else:
        start = 1

    if types == 1:  # 1代表spark
        for i in range(start, start + num):
            name = "spark" + str(i)
            spark(name)
            os.system("kubectl apply -f %s/static/cluster/spark1.yaml" % url)
    elif types == 2:  # 2代表Hadoop
        for i in range(start, start + num):
            name = "hadoop" + str(i)
            hadoop(name)
            os.system("kubectl apply -f %s/static/cluster/hadoop1.yaml" % url)
    return start
